import Sprite from '../base/Sprite'
import DataStore from '../base/DataStore'

export default class Land extends Sprite {
  constructor() {
    const image = Sprite.getImage('land')
    const dataStore = DataStore.getInstance()
    super(
      image,
      0,
      0,
      image.width,
      image.height,
      0,
      dataStore.screenHeight - image.height,
      image.width,
      image.height
    )
    this.landX = 0
    this.landSpeed = dataStore.landSpeed
  }

  draw() {
    this.landX = this.landX + this.landSpeed
    if (this.landX > this.img.width - this.dataStore.screenWidth) {
      this.landX = 0
    }
    super.draw(
      this.img,
      this.srcX,
      this.srcY,
      this.srcW,
      this.srcH,
      -this.landX,
      this.y,
      this.width,
      this.height
    )
  }
}